﻿using System;
using FireStarter.Base;
using FireStarter.Base.BusinessObjectMerger;
using Firestarter.DB.Schema.BO;
using Firestarter.DB.Schema.Logic;
using FireStarterModeller.BO;
using FireStarterModeller.Logic.MergeBusinessObjects;
using Habanero.Base;
using NUnit.Framework;
using Firestarter.DB.Schema.Test.Logic;

namespace Firestarter.DB.Schema.Test.Logic.DBMerge
{
    public class DBBusinessObjectMerger
    {
        private IMergeBO _mergeBO;

        public DBBusinessObjectMerger(IMergableBo existingBO, Predicate<IBOProp> ignorePropertyDelegate)
        {
            MergeableBORegistry.Instance.Register<DBDatabase, DBMergeBO<DBDatabase>>();
            MergeableBORegistry.Instance.Register<DBTable, DBMergeBO<DBTable>>();
            MergeableBORegistry.Instance.Register<DBColumn, DBMergeBO<DBColumn>>();
            MergeableBORegistry.Instance.Register<DBPrimaryKey, DBMergeBO<DBPrimaryKey>>();
            MergeableBORegistry.Instance.Register<DBPrimaryKeyColumn, DBMergeBO<DBPrimaryKeyColumn>>();
            MergeableBORegistry.Instance.Register<DBKey, DBMergeBO<DBKey>>();
            MergeableBORegistry.Instance.Register<DBKeyColumn, DBMergeBO<DBKeyColumn>>();
            MergeableBORegistry.Instance.Register<DBForeignKey, DBMergeDBForeignKey>();
            MergeableBORegistry.Instance.Register<DBForeignKeyColumn, DBMergeBO<DBForeignKeyColumn>>();

            ExistingMergableBo = existingBO;
            if (ExistingMergableBo != null) _mergeBO = MergeableBORegistry.Instance.Resolve(ExistingMergableBo.GetType());

        }

        public IMergableBo ExistingMergableBo { get; private set; }

        public void Import(IMergableBo mergableBo)
        {
            if (_mergeBO == null && mergableBo != null) _mergeBO = MergeableBORegistry.Instance.Resolve(mergableBo.GetType());
            if (_mergeBO == null && ExistingMergableBo != null) _mergeBO = MergeableBORegistry.Instance.Resolve(ExistingMergableBo.GetType());
            if (_mergeBO != null) ExistingMergableBo = _mergeBO.MergeBOFrom(mergableBo, ExistingMergableBo) as IMergableBo;
        }
    }


    //[TestFixture]
    //public class TestBusinessObjectMerger : TestBase
    //{
    //    // Test the constructor
    //    [Test]
    //    public void Test_Constructor()
    //    {
    //        //---------------Set up test pack-------------------
    //        DBDatabase dbDatabase = new DBDatabase();
    //        //---------------Assert Precondition----------------

    //        //---------------Execute Test ----------------------
    //        DBBusinessObjectMerger dbBusinessObjectMerger = new DBBusinessObjectMerger(dbDatabase, null);
    //        //---------------Test Result -----------------------
    //        Assert.AreSame(dbDatabase, dbBusinessObjectMerger.ExistingMergableBo);
    //    }

    //    [Test]
    //    public void Test_Import_BothNull()
    //    {
    //        //---------------Set up test pack-------------------
    //        DBBusinessObjectMerger dbBusinessObjectMerger = new DBBusinessObjectMerger(null, null);
    //        //---------------Assert Precondition----------------
    //        //---------------Execute Test ----------------------
    //        dbBusinessObjectMerger.Import(null);
    //        //---------------Test Result -----------------------
    //        //There should be no errors
    //        Assert.IsNull(dbBusinessObjectMerger.ExistingMergableBo);
    //    }

    //    [Test]
    //    public void Test_Import_ExistingIsNull()
    //    {
    //        //---------------Set up test pack-------------------
    //        DBDatabase newDBDatabase = new DBDatabase();
    //        DBBusinessObjectMerger dbBusinessObjectMerger = new DBBusinessObjectMerger(null, null);
    //        //---------------Assert Precondition----------------
    //        Assert.AreEqual(0, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(ChangeType.None, newDBDatabase.PendingChangeType);
    //        Assert.IsNull(dbBusinessObjectMerger.ExistingMergableBo);
    //        //---------------Execute Test ----------------------
    //        dbBusinessObjectMerger.Import(newDBDatabase);
    //        //---------------Test Result -----------------------
    //        //There should be no errors
    //        Assert.IsNotNull(dbBusinessObjectMerger.ExistingMergableBo);
    //        Assert.AreSame(newDBDatabase, dbBusinessObjectMerger.ExistingMergableBo);
    //        Assert.AreEqual(ChangeType.Add, newDBDatabase.PendingChangeType);
    //    }

    //    [Test]
    //    public void Test_Import_NewIsNull()
    //    {
    //        //---------------Set up test pack-------------------
    //        DBDatabase existingDBDatabase = new DBDatabase();
    //        DBBusinessObjectMerger dbBusinessObjectMerger = new DBBusinessObjectMerger(existingDBDatabase, null);
    //        //---------------Assert Precondition----------------
    //        Assert.AreEqual(0, existingDBDatabase.Tables.Count);
    //        Assert.AreEqual(ChangeType.None, existingDBDatabase.PendingChangeType);
    //        //---------------Execute Test ----------------------
    //        dbBusinessObjectMerger.Import(null);
    //        //---------------Test Result -----------------------
    //        //There should be no errors
    //        Assert.IsNotNull(dbBusinessObjectMerger.ExistingMergableBo);
    //        Assert.AreSame(existingDBDatabase, dbBusinessObjectMerger.ExistingMergableBo);
    //        Assert.AreEqual(ChangeType.Delete, existingDBDatabase.PendingChangeType);
    //    }

    //    // Test the situation where both databases are empty
    //    [Test]
    //    public void Test_Import_BothDatabasesEmpty()
    //    {
    //        //---------------Set up test pack-------------------
    //        DBDatabase newDBDatabase = new DBDatabase();
    //        DBDatabase existingDBDatabase = new DBDatabase();
    //        DBBusinessObjectMerger dbBusinessObjectMerger = new DBBusinessObjectMerger(existingDBDatabase, null);
    //        //---------------Assert Precondition----------------
    //        Assert.AreEqual(0, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(0, existingDBDatabase.Tables.Count);
    //        //---------------Execute Test ----------------------
    //        dbBusinessObjectMerger.Import(newDBDatabase);
    //        //---------------Test Result -----------------------
    //        Assert.AreEqual(0, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(0, existingDBDatabase.Tables.Count);
    //    }

    //    // Test the situation where a database has been updated
    //    [Test]
    //    public void Test_Import_Databases_Updated()
    //    {
    //        //---------------Set up test pack-------------------
    //        DBDatabase newDBDatabase = new DBDatabase();
    //        newDBDatabase.DatabaseName = TestUtils.GetRandomString();
    //        newDBDatabase.Catalog = TestUtils.GetRandomString();
    //        newDBDatabase.Schema = TestUtils.GetRandomString();

    //        DBDatabase existingDBDatabase = new DBDatabase();
    //        existingDBDatabase.DatabaseName = TestUtils.GetRandomString();
    //        existingDBDatabase.Catalog = TestUtils.GetRandomString();
    //        existingDBDatabase.Schema = TestUtils.GetRandomString();

    //        //---------------Assert Precondition----------------

    //        //---------------Execute Test ----------------------
    //        DBBusinessObjectMerger dbBusinessObjectMerger = new DBBusinessObjectMerger(existingDBDatabase, null);
    //        dbBusinessObjectMerger.Import(newDBDatabase);
    //        //---------------Test Result -----------------------
    //        Assert.AreEqual(newDBDatabase.DatabaseName, existingDBDatabase.DatabaseName);
    //        Assert.AreEqual(newDBDatabase.Catalog, existingDBDatabase.Catalog);
    //        Assert.AreEqual(newDBDatabase.Schema, existingDBDatabase.Schema);
    //    }

    //    // Test the situation where a database has been updated
    //    [Test]
    //    public void Test_Import_Databases_Same_PendingChangeTypeDiffers()
    //    {
    //        //---------------Set up test pack-------------------
    //        DBDatabase existingDBDatabase = new DBDatabase();
    //        existingDBDatabase.DatabaseName = TestUtils.GetRandomString();
    //        existingDBDatabase.Catalog = TestUtils.GetRandomString();
    //        existingDBDatabase.Schema = TestUtils.GetRandomString();
    //        existingDBDatabase.PendingChangeType = ChangeType.Add;

    //        DBDatabase newDBDatabase = new DBDatabase();
    //        newDBDatabase.DatabaseName = existingDBDatabase.DatabaseName;
    //        newDBDatabase.Catalog = existingDBDatabase.Catalog;
    //        newDBDatabase.Schema = existingDBDatabase.Schema;
    //        newDBDatabase.PendingChangeType = ChangeType.None;

    //        //---------------Assert Precondition----------------

    //        //---------------Execute Test ----------------------
    //        DBBusinessObjectMerger dbBusinessObjectMerger = new DBBusinessObjectMerger(existingDBDatabase, null);
    //        dbBusinessObjectMerger.Import(newDBDatabase);
    //        //---------------Test Result -----------------------
    //        Assert.AreEqual(ChangeType.Add, existingDBDatabase.PendingChangeType);
    //    }

    //    // Test the situation where both databases have the same table
    //    [Test]
    //    public void Test_Import_DatabasesEqual_SameTable()
    //    {
    //        //---------------Set up test pack-------------------
    //        DBDatabase newDBDatabase = new DBDatabase();
    //        string tableName = TestUtils.GetRandomString();
    //        DBTable newDBTable = new DBTable(tableName);
    //        newDBDatabase.Tables.Add(newDBTable);
    //        DBDatabase existingDBDatabase = new DBDatabase();
    //        DBTable existingDBTable = new DBTable(tableName);
    //        existingDBDatabase.Tables.Add(existingDBTable);

    //        //---------------Assert Precondition----------------
    //        Assert.AreEqual(1, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables.Count);
    //        Assert.AreEqual(ChangeType.None, existingDBTable.PendingChangeType);
    //        //---------------Execute Test ----------------------
    //        DBBusinessObjectMerger dbBusinessObjectMerger = new DBBusinessObjectMerger(existingDBDatabase, null);
    //        dbBusinessObjectMerger.Import(newDBDatabase);
    //        //---------------Test Result -----------------------
    //        Assert.AreEqual(1, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables.Count);
    //        Assert.AreSame(existingDBTable, existingDBDatabase.Tables[0]);
    //        Assert.AreEqual(ChangeType.None, existingDBTable.PendingChangeType);
    //    }

    //    // Test the situation where a Database Table has been Added
    //    [Test]
    //    public void Test_Import_TableAdded()
    //    {
    //        //---------------Set up test pack-------------------
    //        DBDatabase newDBDatabase = new DBDatabase();
    //        DBTable dbTable = new DBTable(TestUtils.GetRandomString());
    //        newDBDatabase.Tables.Add(dbTable);
    //        DBDatabase existingDBDatabase = new DBDatabase();
    //        //---------------Assert Precondition----------------
    //        Assert.AreEqual(1, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(0, existingDBDatabase.Tables.Count);
    //        Assert.AreEqual(ChangeType.None, dbTable.PendingChangeType);
    //        //---------------Execute Test ----------------------
    //        DBBusinessObjectMerger dbBusinessObjectMerger = new DBBusinessObjectMerger(existingDBDatabase, null);
    //        dbBusinessObjectMerger.Import(newDBDatabase);
    //        //---------------Test Result -----------------------
    //        Assert.AreEqual(1, existingDBDatabase.Tables.Count);
    //        Assert.AreSame(dbTable, existingDBDatabase.Tables[0]);
    //        Assert.AreEqual(0, newDBDatabase.Tables.Count, "Table should have been moved");
    //        Assert.AreEqual(ChangeType.Add, dbTable.PendingChangeType);
    //    }

    //    // Test the situation where a Database Table has been Added
    //    [Test]
    //    public void Test_Import_TableAdded_WithColumns()
    //    {
    //        //---------------Set up test pack-------------------
    //        DBDatabase newDBDatabase = new DBDatabase();
    //        DBTable dbTable = new DBTable(TestUtils.GetRandomString());
    //        newDBDatabase.Tables.Add(dbTable);
    //        DBColumn dbColumn = new DBColumn(TestUtils.GetRandomString());
    //        dbTable.Columns.Add(dbColumn);

    //        DBDatabase existingDBDatabase = new DBDatabase();
    //        //---------------Assert Precondition----------------
    //        Assert.AreEqual(1, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(0, existingDBDatabase.Tables.Count);
    //        Assert.AreEqual(ChangeType.None, dbTable.PendingChangeType);
    //        Assert.AreEqual(1, dbTable.Columns.Count);
    //        Assert.AreEqual(ChangeType.None, dbColumn.PendingChangeType);
    //        //---------------Execute Test ----------------------
    //        DBBusinessObjectMerger dbBusinessObjectMerger = new DBBusinessObjectMerger(existingDBDatabase, null);
    //        dbBusinessObjectMerger.Import(newDBDatabase);
    //        //---------------Test Result -----------------------
    //        Assert.AreEqual(1, existingDBDatabase.Tables.Count);
    //        Assert.AreSame(dbTable, existingDBDatabase.Tables[0]);
    //        Assert.AreEqual(0, newDBDatabase.Tables.Count, "Table should have been moved");
    //        Assert.AreEqual(ChangeType.Add, dbTable.PendingChangeType);
    //        Assert.AreEqual(ChangeType.Add, dbColumn.PendingChangeType);
    //    }

    //    // Test the situation where a Database Table has been Added
    //    [Test]
    //    public void Test_Import_TableAdded_WithPrimaryKey()
    //    {
    //        //---------------Set up test pack-------------------
    //        DBDatabase newDBDatabase = new DBDatabase();
    //        DBTable dbTable = new DBTable(TestUtils.GetRandomString());
    //        newDBDatabase.Tables.Add(dbTable);
    //        DBPrimaryKey dbPrimaryKey = new DBPrimaryKey();
    //        dbTable.PrimaryKeyDB = dbPrimaryKey;

    //        DBDatabase existingDBDatabase = new DBDatabase();
    //        //---------------Assert Precondition----------------
    //        Assert.AreEqual(1, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(0, existingDBDatabase.Tables.Count);
    //        Assert.AreEqual(ChangeType.None, dbTable.PendingChangeType);
    //        Assert.AreEqual(ChangeType.None, dbPrimaryKey.PendingChangeType);
    //        //---------------Execute Test ----------------------
    //        DBBusinessObjectMerger dbBusinessObjectMerger = new DBBusinessObjectMerger(existingDBDatabase, null);
    //        dbBusinessObjectMerger.Import(newDBDatabase);
    //        //---------------Test Result -----------------------
    //        Assert.AreEqual(1, existingDBDatabase.Tables.Count);
    //        Assert.AreSame(dbTable, existingDBDatabase.Tables[0]);
    //        Assert.AreEqual(0, newDBDatabase.Tables.Count, "Table should have been moved");
    //        Assert.AreEqual(ChangeType.Add, dbTable.PendingChangeType);
    //        Assert.AreEqual(ChangeType.Add, dbPrimaryKey.PendingChangeType);
    //    }

    //    // Test the situation where a Database Table has been Added
    //    [Test]
    //    public void Test_Import_TableAdded_WithPrimaryKey_WithPKColumns()
    //    {
    //        //---------------Set up test pack-------------------
    //        DBDatabase newDBDatabase = new DBDatabase();
    //        DBTable dbTable = new DBTable(TestUtils.GetRandomString());
    //        newDBDatabase.Tables.Add(dbTable);
    //        DBColumn dbColumn = new DBColumn(TestUtils.GetRandomString());
    //        dbTable.Columns.Add(dbColumn);
    //        DBPrimaryKey dbPrimaryKey = new DBPrimaryKey();
    //        dbTable.PrimaryKeyDB = dbPrimaryKey;
    //        DBPrimaryKeyColumn dbPrimaryKeyColumn = dbPrimaryKey.AddColumnInfo(dbColumn);

    //        DBDatabase existingDBDatabase = new DBDatabase();
    //        //---------------Assert Precondition----------------
    //        Assert.AreEqual(1, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(0, existingDBDatabase.Tables.Count);
    //        Assert.AreEqual(ChangeType.None, dbTable.PendingChangeType);
    //        Assert.AreEqual(ChangeType.None, dbPrimaryKey.PendingChangeType);
    //        Assert.AreEqual(ChangeType.None, dbPrimaryKeyColumn.PendingChangeType);
    //        //---------------Execute Test ----------------------
    //        DBBusinessObjectMerger dbBusinessObjectMerger = new DBBusinessObjectMerger(existingDBDatabase, null);
    //        dbBusinessObjectMerger.Import(newDBDatabase);
    //        //---------------Test Result -----------------------
    //        Assert.AreEqual(1, existingDBDatabase.Tables.Count);
    //        Assert.AreSame(dbTable, existingDBDatabase.Tables[0]);
    //        Assert.AreEqual(0, newDBDatabase.Tables.Count, "Table should have been moved");
    //        Assert.AreEqual(ChangeType.Add, dbTable.PendingChangeType);
    //        Assert.AreEqual(ChangeType.Add, dbPrimaryKey.PendingChangeType);
    //        Assert.AreEqual(ChangeType.Add, dbPrimaryKeyColumn.PendingChangeType);
    //    }

    //    // Test the situation where a Database Table has been Added
    //    [Test]
    //    public void Test_Import_TableAdded_WithAlternateKey()
    //    {
    //        //---------------Set up test pack-------------------
    //        DBDatabase newDBDatabase = new DBDatabase();
    //        DBTable dbTable = new DBTable(TestUtils.GetRandomString());
    //        newDBDatabase.Tables.Add(dbTable);
    //        DBKey dbKey = new DBKey { KeyName = TestUtils.GetRandomString() };
    //        dbTable.Keys.Add(dbKey);

    //        DBDatabase existingDBDatabase = new DBDatabase();
    //        //---------------Assert Precondition----------------
    //        Assert.AreEqual(1, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(0, existingDBDatabase.Tables.Count);
    //        Assert.AreEqual(ChangeType.None, dbTable.PendingChangeType);
    //        Assert.AreEqual(ChangeType.None, dbKey.PendingChangeType);
    //        //---------------Execute Test ----------------------
    //        DBBusinessObjectMerger dbBusinessObjectMerger = new DBBusinessObjectMerger(existingDBDatabase, null);
    //        dbBusinessObjectMerger.Import(newDBDatabase);
    //        //---------------Test Result -----------------------
    //        Assert.AreEqual(1, existingDBDatabase.Tables.Count);
    //        Assert.AreSame(dbTable, existingDBDatabase.Tables[0]);
    //        Assert.AreEqual(0, newDBDatabase.Tables.Count, "Table should have been moved");
    //        Assert.AreEqual(ChangeType.Add, dbTable.PendingChangeType);
    //        Assert.AreEqual(ChangeType.Add, dbKey.PendingChangeType);
    //    }

    //    // Test the situation where a Database Table has been Added
    //    [Test]
    //    public void Test_Import_TableAdded_WithAlternateKey_WithAKColumns()
    //    {
    //        //---------------Set up test pack-------------------
    //        DBDatabase newDBDatabase = new DBDatabase();
    //        DBTable dbTable = new DBTable(TestUtils.GetRandomString());
    //        newDBDatabase.Tables.Add(dbTable);
    //        DBColumn dbColumn = new DBColumn(TestUtils.GetRandomString());
    //        dbTable.Columns.Add(dbColumn);
    //        DBKey dbKey = new DBKey { KeyName = TestUtils.GetRandomString() };
    //        dbTable.Keys.Add(dbKey);
    //        DBKeyColumn dbKeyColumn = dbKey.AddColumnInfo(dbColumn);

    //        DBDatabase existingDBDatabase = new DBDatabase();
    //        //---------------Assert Precondition----------------
    //        Assert.AreEqual(1, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(0, existingDBDatabase.Tables.Count);
    //        Assert.AreEqual(ChangeType.None, dbTable.PendingChangeType);
    //        Assert.AreEqual(ChangeType.None, dbKey.PendingChangeType);
    //        Assert.AreEqual(ChangeType.None, dbKeyColumn.PendingChangeType);
    //        //---------------Execute Test ----------------------
    //        DBBusinessObjectMerger dbBusinessObjectMerger = new DBBusinessObjectMerger(existingDBDatabase, null);
    //        dbBusinessObjectMerger.Import(newDBDatabase);
    //        //---------------Test Result -----------------------
    //        Assert.AreEqual(1, existingDBDatabase.Tables.Count);
    //        Assert.AreSame(dbTable, existingDBDatabase.Tables[0]);
    //        Assert.AreEqual(0, newDBDatabase.Tables.Count, "Table should have been moved");
    //        Assert.AreEqual(ChangeType.Add, dbTable.PendingChangeType);
    //        Assert.AreEqual(ChangeType.Add, dbKey.PendingChangeType);
    //        Assert.AreEqual(ChangeType.Add, dbKeyColumn.PendingChangeType);
    //    }

    //    // Test the situation where a Database Table has been Added
    //    [Test]
    //    public void Test_Import_TableAdded_WithForeignKey()
    //    {
    //        //---------------Set up test pack-------------------
    //        DBDatabase newDBDatabase = new DBDatabase();
    //        DBTable dbTable = new DBTable(TestUtils.GetRandomString());
    //        newDBDatabase.Tables.Add(dbTable);
    //        DBForeignKey dbForeignKey = new DBForeignKey();
    //        dbTable.ForeignKeys.Add(dbForeignKey);

    //        DBDatabase existingDBDatabase = new DBDatabase();
    //        //---------------Assert Precondition----------------
    //        Assert.AreEqual(1, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(0, existingDBDatabase.Tables.Count);
    //        Assert.AreEqual(ChangeType.None, dbTable.PendingChangeType);
    //        Assert.AreEqual(ChangeType.None, dbForeignKey.PendingChangeType);
    //        //---------------Execute Test ----------------------
    //        DBBusinessObjectMerger dbBusinessObjectMerger = new DBBusinessObjectMerger(existingDBDatabase, null);
    //        dbBusinessObjectMerger.Import(newDBDatabase);
    //        //---------------Test Result -----------------------
    //        Assert.AreEqual(1, existingDBDatabase.Tables.Count);
    //        Assert.AreSame(dbTable, existingDBDatabase.Tables[0]);
    //        Assert.AreEqual(0, newDBDatabase.Tables.Count, "Table should have been moved");
    //        Assert.AreEqual(ChangeType.Add, dbTable.PendingChangeType);
    //        Assert.AreEqual(ChangeType.Add, dbForeignKey.PendingChangeType);
    //    }

    //    // Test the situation where a Database Table has been Deleted
    //    [Test]
    //    public void Test_Import_TableDeleted()
    //    {
    //        //---------------Set up test pack-------------------
    //        DBDatabase newDBDatabase = new DBDatabase();
    //        DBDatabase existingDBDatabase = new DBDatabase();
    //        DBTable dbTable = new DBTable(TestUtils.GetRandomString());
    //        existingDBDatabase.Tables.Add(dbTable);

    //        //---------------Assert Precondition----------------
    //        Assert.AreEqual(0, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables.Count);
    //        Assert.AreEqual(ChangeType.None, dbTable.PendingChangeType);
    //        //---------------Execute Test ----------------------
    //        DBBusinessObjectMerger dbBusinessObjectMerger = new DBBusinessObjectMerger(existingDBDatabase, null);
    //        dbBusinessObjectMerger.Import(newDBDatabase);
    //        //---------------Test Result -----------------------
    //        Assert.AreEqual(0, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables.Count);
    //        Assert.AreSame(dbTable, existingDBDatabase.Tables[0]);
    //        Assert.AreEqual(ChangeType.Delete, dbTable.PendingChangeType);
    //    }

    //    // Test the situation where a Database Table has been Updated
    //    [Test]
    //    public void Test_Import_TableUpdated()
    //    {
    //        //---------------Set up test pack-------------------
    //        DBDatabase newDBDatabase = new DBDatabase();
    //        string tableName = TestUtils.GetRandomString();
    //        DBTable newDBTable = new DBTable(tableName);
    //        string newTableComment = TestUtils.GetRandomString();
    //        newDBTable.TableComment = newTableComment;
    //        newDBDatabase.Tables.Add(newDBTable);
    //        DBDatabase existingDBDatabase = new DBDatabase();
    //        DBTable existingDBTable = new DBTable(tableName);
    //        existingDBTable.TableComment = TestUtils.GetRandomString();
    //        existingDBDatabase.Tables.Add(existingDBTable);

    //        //---------------Assert Precondition----------------
    //        Assert.AreEqual(1, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables.Count);
    //        Assert.AreEqual(ChangeType.None, existingDBTable.PendingChangeType);
    //        //---------------Execute Test ----------------------
    //        DBBusinessObjectMerger dbBusinessObjectMerger = new DBBusinessObjectMerger(existingDBDatabase, null);
    //        dbBusinessObjectMerger.Import(newDBDatabase);
    //        //---------------Test Result -----------------------
    //        Assert.AreEqual(1, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables.Count);
    //        Assert.AreSame(existingDBTable, existingDBDatabase.Tables[0]);
    //        Assert.AreEqual(newTableComment, existingDBTable.TableComment);
    //        Assert.AreEqual(ChangeType.Update, existingDBTable.PendingChangeType);
    //    }

    //    // Test the situation where a Database Table has been Updated
    //    [Test]
    //    public void Test_Import_TableUnchanged()
    //    {
    //        //---------------Set up test pack-------------------
    //        string tableName = TestUtils.GetRandomString();
    //        DBDatabase existingDBDatabase = new DBDatabase();
    //        DBTable existingDBTable = new DBTable(tableName)
    //        {
    //            TableComment = TestUtils.GetRandomString()
    //        };
    //        existingDBDatabase.Tables.Add(existingDBTable);

    //        DBDatabase newDBDatabase = new DBDatabase();
    //        DBTable newDBTable = new DBTable(tableName)
    //        {
    //            TableComment = existingDBTable.TableComment
    //        };
    //        newDBDatabase.Tables.Add(newDBTable);

    //        //---------------Assert Precondition----------------
    //        Assert.AreEqual(1, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables.Count);
    //        Assert.AreEqual(ChangeType.None, existingDBTable.PendingChangeType);
    //        //---------------Execute Test ----------------------
    //        DBBusinessObjectMerger dbBusinessObjectMerger = new DBBusinessObjectMerger(existingDBDatabase, null);
    //        dbBusinessObjectMerger.Import(newDBDatabase);
    //        //---------------Test Result -----------------------
    //        Assert.AreEqual(1, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables.Count);
    //        Assert.AreSame(existingDBTable, existingDBDatabase.Tables[0]);
    //        Assert.AreEqual(ChangeType.None, existingDBTable.PendingChangeType);
    //    }

    //    // Test the situation where a Database Table has been Updated
    //    [Test]
    //    public void Test_Import_TableUnchanged_WithIgnoredPropDifferent()
    //    {
    //        //---------------Set up test pack-------------------
    //        string tableName = TestUtils.GetRandomString();
    //        DBDatabase existingDBDatabase = new DBDatabase();
    //        DBTable existingDBTable = new DBTable(tableName)
    //        {
    //            TableComment = TestUtils.GetRandomString(),
    //            Approved = true
    //        };
    //        existingDBDatabase.Tables.Add(existingDBTable);

    //        DBDatabase newDBDatabase = new DBDatabase();
    //        DBTable newDBTable = new DBTable(tableName)
    //        {
    //            TableComment = existingDBTable.TableComment,
    //            Approved = false
    //        };
    //        newDBDatabase.Tables.Add(newDBTable);

    //        //---------------Assert Precondition----------------
    //        Assert.AreEqual(1, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables.Count);
    //        Assert.AreEqual(ChangeType.None, existingDBTable.PendingChangeType);
    //        //---------------Execute Test ----------------------
    //        DBBusinessObjectMerger dbBusinessObjectMerger = new DBBusinessObjectMerger(existingDBDatabase, prop => prop.PropertyName == "Approved");
    //        dbBusinessObjectMerger.Import(newDBDatabase);
    //        //---------------Test Result -----------------------
    //        Assert.AreEqual(1, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables.Count);
    //        Assert.AreSame(existingDBTable, existingDBDatabase.Tables[0]);
    //        Assert.AreEqual(ChangeType.None, existingDBTable.PendingChangeType);
    //    }

    //    // Test the situation where a Database Column has been Added
    //    [Test]
    //    public void Test_Import_SameTable_ColumnAdded()
    //    {
    //        //---------------Set up test pack-------------------
    //        DBDatabase newDBDatabase = new DBDatabase();
    //        DBTable dbTable = new DBTable(TestUtils.GetRandomString());
    //        newDBDatabase.Tables.Add(dbTable);
    //        DBColumn dbColumn = new DBColumn(TestUtils.GetRandomString());
    //        dbTable.Columns.Add(dbColumn);

    //        DBDatabase existingDBDatabase = new DBDatabase();
    //        DBTable existingDBTable = new DBTable(dbTable.TableName);
    //        existingDBDatabase.Tables.Add(existingDBTable);
    //        //---------------Assert Precondition----------------
    //        Assert.AreEqual(1, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, newDBDatabase.Tables[0].Columns.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables.Count);
    //        Assert.AreEqual(0, existingDBDatabase.Tables[0].Columns.Count);
    //        Assert.AreEqual(ChangeType.None, dbColumn.PendingChangeType);
    //        //---------------Execute Test ----------------------
    //        DBBusinessObjectMerger dbBusinessObjectMerger = new DBBusinessObjectMerger(existingDBDatabase, null);
    //        dbBusinessObjectMerger.Import(newDBDatabase);
    //        //---------------Test Result -----------------------
    //        Assert.AreEqual(1, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, existingDBTable.Columns.Count);
    //        Assert.AreSame(dbColumn, existingDBTable.Columns[0]);
    //        Assert.AreEqual(0, dbTable.Columns.Count, "Column should have been moved");
    //        Assert.AreEqual(ChangeType.Add, dbColumn.PendingChangeType);
    //        Assert.AreEqual(ChangeType.Update, existingDBTable.PendingChangeType);
    //    }

    //    // Test the situation where a Database Column has been Deleted
    //    [Test]
    //    public void Test_Import_SameTable_ColumnDeleted()
    //    {
    //        //---------------Set up test pack-------------------
    //        DBDatabase newdatabase = new DBDatabase();
    //        DBTable newtable = new DBTable(TestUtils.GetRandomString());
    //        newdatabase.Tables.Add(newtable);

    //        DBDatabase existingdatabase = new DBDatabase();
    //        DBTable existingDBTable = new DBTable(newtable.TableName);
    //        existingdatabase.Tables.Add(existingDBTable);
    //        DBColumn existingcolumn = new DBColumn(TestUtils.GetRandomString());
    //        existingDBTable.Columns.Add(existingcolumn);
    //        //---------------Assert Precondition----------------
    //        Assert.AreEqual(1, newdatabase.Tables.Count);
    //        Assert.AreEqual(0, newdatabase.Tables[0].Columns.Count);
    //        Assert.AreEqual(1, existingdatabase.Tables.Count);
    //        Assert.AreEqual(1, existingdatabase.Tables[0].Columns.Count);
    //        Assert.AreEqual(ChangeType.None, existingcolumn.PendingChangeType);
    //        Assert.AreEqual(ChangeType.None, existingDBTable.PendingChangeType);
    //        //---------------Execute Test ----------------------
    //        DBBusinessObjectMerger dbBusinessObjectMerger = new DBBusinessObjectMerger(existingdatabase, null);
    //        dbBusinessObjectMerger.Import(newdatabase);
    //        //---------------Test Result -----------------------
    //        Assert.AreEqual(1, newdatabase.Tables.Count);
    //        Assert.AreEqual(0, newdatabase.Tables[0].Columns.Count);
    //        Assert.AreEqual(1, existingdatabase.Tables.Count);
    //        Assert.AreEqual(1, existingdatabase.Tables[0].Columns.Count);
    //        Assert.AreEqual(ChangeType.Delete, existingcolumn.PendingChangeType);
    //        Assert.AreEqual(ChangeType.Update, existingDBTable.PendingChangeType);
    //    }

    //    // Test the situation where a Database Column has been Updated
    //    [Test]
    //    public void Test_Import_SameTable_ColumnUpdated()
    //    {
    //        //---------------Set up test pack-------------------

    //        DBDatabase newdatabase = new DBDatabase();
    //        DBTable newtable = new DBTable(TestUtils.GetRandomString());
    //        newdatabase.Tables.Add(newtable);
    //        DBColumn newDBColumn = new DBColumn(TestUtils.GetRandomString());
    //        newtable.Columns.Add(newDBColumn);
    //        string newColumnComment = TestUtils.GetRandomString();
    //        newDBColumn.Comment = newColumnComment;

    //        DBDatabase existingdatabase = new DBDatabase();
    //        DBTable existingtable = new DBTable(newtable.TableName);
    //        existingdatabase.Tables.Add(existingtable);
    //        DBColumn existingDBColumn = new DBColumn(newDBColumn.ColumnName);
    //        existingtable.Columns.Add(existingDBColumn);
    //        existingDBColumn.Comment = TestUtils.GetRandomString();

    //        //---------------Assert Precondition----------------
    //        Assert.AreEqual(1, newdatabase.Tables.Count);
    //        Assert.AreEqual(1, newdatabase.Tables[0].Columns.Count);
    //        Assert.AreEqual(1, existingdatabase.Tables.Count);
    //        Assert.AreEqual(1, existingdatabase.Tables[0].Columns.Count);
    //        Assert.AreEqual(ChangeType.None, existingDBColumn.PendingChangeType);
    //        Assert.AreEqual(ChangeType.None, existingtable.PendingChangeType);

    //        //---------------Execute Test ----------------------
    //        DBBusinessObjectMerger dbBusinessObjectMerger = new DBBusinessObjectMerger(existingdatabase, null);
    //        dbBusinessObjectMerger.Import(newdatabase);
    //        //---------------Test Result -----------------------
    //        Assert.AreEqual(1, newdatabase.Tables.Count);
    //        Assert.AreEqual(1, newdatabase.Tables[0].Columns.Count);
    //        Assert.AreEqual(1, existingdatabase.Tables.Count);
    //        Assert.AreEqual(1, existingdatabase.Tables[0].Columns.Count);
    //        Assert.AreEqual(newColumnComment, existingDBColumn.Comment);
    //        Assert.AreEqual(ChangeType.Update, existingtable.PendingChangeType);
    //        Assert.AreEqual(ChangeType.Update, existingDBColumn.PendingChangeType);
    //    }

    //    // Test the situation where a Database Key has been Added
    //    [Test]
    //    public void Test_Import_SameTable_KeyAdded()
    //    {
    //        //---------------Set up test pack-------------------
    //        DBDatabase newDBDatabase = new DBDatabase();
    //        DBTable dbTable = new DBTable(TestUtils.GetRandomString());
    //        newDBDatabase.Tables.Add(dbTable);
    //        DBKey dbKey = new DBKey { KeyName = TestUtils.GetRandomString() };
    //        dbTable.Keys.Add(dbKey);

    //        DBDatabase existingDBDatabase = new DBDatabase();
    //        DBTable existingDBTable = new DBTable(dbTable.TableName);
    //        existingDBDatabase.Tables.Add(existingDBTable);
    //        //---------------Assert Precondition----------------
    //        Assert.AreEqual(1, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, newDBDatabase.Tables[0].Keys.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables.Count);
    //        Assert.AreEqual(0, existingDBDatabase.Tables[0].Keys.Count);
    //        Assert.AreEqual(ChangeType.None, dbKey.PendingChangeType);
    //        //---------------Execute Test ----------------------
    //        DBBusinessObjectMerger dbBusinessObjectMerger = new DBBusinessObjectMerger(existingDBDatabase, null);
    //        dbBusinessObjectMerger.Import(newDBDatabase);
    //        //---------------Test Result -----------------------
    //        Assert.AreEqual(1, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, existingDBTable.Keys.Count);
    //        Assert.AreSame(dbKey, existingDBTable.Keys[0]);
    //        Assert.AreEqual(0, dbTable.Keys.Count, "DBKey should have been moved");
    //        Assert.AreEqual(ChangeType.Add, dbKey.PendingChangeType);
    //        Assert.AreEqual(ChangeType.Update, existingDBTable.PendingChangeType);
    //    }

    //    // Test the situation where a Database Key has been Deleted
    //    [Test]
    //    public void Test_Import_SameTable_KeyDeleted()
    //    {
    //        //---------------Set up test pack-------------------
    //        DBDatabase newdatabase = new DBDatabase();
    //        DBTable newtable = new DBTable(TestUtils.GetRandomString());
    //        newdatabase.Tables.Add(newtable);

    //        DBDatabase existingdatabase = new DBDatabase();
    //        DBTable existingDBTable = new DBTable(newtable.TableName);
    //        existingdatabase.Tables.Add(existingDBTable);
    //        DBKey existingDBKey = new DBKey { KeyName = TestUtils.GetRandomString() };
    //        existingDBTable.Keys.Add(existingDBKey);
    //        //---------------Assert Precondition----------------
    //        Assert.AreEqual(1, newdatabase.Tables.Count);
    //        Assert.AreEqual(0, newdatabase.Tables[0].Keys.Count);
    //        Assert.AreEqual(1, existingdatabase.Tables.Count);
    //        Assert.AreEqual(1, existingdatabase.Tables[0].Keys.Count);
    //        Assert.AreEqual(ChangeType.None, existingDBKey.PendingChangeType);
    //        Assert.AreEqual(ChangeType.None, existingDBTable.PendingChangeType);
    //        //---------------Execute Test ----------------------
    //        DBBusinessObjectMerger dbBusinessObjectMerger = new DBBusinessObjectMerger(existingdatabase, null);
    //        dbBusinessObjectMerger.Import(newdatabase);
    //        //---------------Test Result -----------------------
    //        Assert.AreEqual(1, newdatabase.Tables.Count);
    //        Assert.AreEqual(0, newdatabase.Tables[0].Keys.Count);
    //        Assert.AreEqual(1, existingdatabase.Tables.Count);
    //        Assert.AreEqual(1, existingdatabase.Tables[0].Keys.Count);
    //        Assert.AreEqual(ChangeType.Delete, existingDBKey.PendingChangeType);
    //        Assert.AreEqual(ChangeType.Update, existingDBTable.PendingChangeType);
    //    }

    //    // Test the situation where a Database Key Column has been Added
    //    [Test]
    //    public void Test_Import_SameTable_KeyColumnAdded()
    //    {
    //        //---------------Set up test pack-------------------
    //        DBDatabase newDBDatabase = new DBDatabase();
    //        DBTable dbTable = new DBTable(TestUtils.GetRandomString());
    //        newDBDatabase.Tables.Add(dbTable);
    //        DBKey dbKey = new DBKey { KeyName = TestUtils.GetRandomString() };
    //        dbTable.Keys.Add(dbKey);
    //        DBKeyColumn dbKeyCol = new DBKeyColumn();
    //        dbKey.KeyColumns.Add(dbKeyCol);

    //        DBDatabase existingDBDatabase = new DBDatabase();
    //        DBTable existingDBTable = new DBTable(dbTable.TableName);
    //        existingDBDatabase.Tables.Add(existingDBTable);
    //        DBKey existingDBKey = new DBKey { KeyName = dbKey.KeyName };
    //        existingDBTable.Keys.Add(existingDBKey);

    //        //---------------Assert Precondition----------------
    //        Assert.AreEqual(1, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, newDBDatabase.Tables[0].Keys.Count);
    //        Assert.AreEqual(1, newDBDatabase.Tables[0].Keys[0].KeyColumns.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables[0].Keys.Count);
    //        Assert.AreEqual(0, existingDBDatabase.Tables[0].Keys[0].KeyColumns.Count);
    //        Assert.AreEqual(ChangeType.None, dbKeyCol.PendingChangeType);
    //        //---------------Execute Test ----------------------
    //        DBBusinessObjectMerger dbBusinessObjectMerger = new DBBusinessObjectMerger(existingDBDatabase, null);
    //        dbBusinessObjectMerger.Import(newDBDatabase);
    //        //---------------Test Result -----------------------
    //        Assert.AreEqual(1, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, newDBDatabase.Tables[0].Keys.Count);
    //        Assert.AreEqual(0, newDBDatabase.Tables[0].Keys[0].KeyColumns.Count, "This is expected to be moved");
    //        Assert.AreEqual(1, existingDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables[0].Keys.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables[0].Keys[0].KeyColumns.Count);

    //        Assert.AreEqual(ChangeType.Add, dbKeyCol.PendingChangeType);
    //        Assert.AreEqual(ChangeType.Update, existingDBKey.PendingChangeType);
    //        Assert.AreEqual(ChangeType.Update, existingDBTable.PendingChangeType);
    //    }

    //    // Test the situation where a Database Key Column has been Deleted
    //    [Test]
    //    public void Test_Import_SameTable_KeyColumnDeleted()
    //    {
    //        //---------------Set up test pack-------------------
    //        DBDatabase newDBDatabase = new DBDatabase();
    //        DBTable dbTable = new DBTable(TestUtils.GetRandomString());
    //        newDBDatabase.Tables.Add(dbTable);
    //        DBKey dbKey = new DBKey { KeyName = TestUtils.GetRandomString() };
    //        dbTable.Keys.Add(dbKey);

    //        DBDatabase existingDBDatabase = new DBDatabase();
    //        DBTable existingDBTable = new DBTable(dbTable.TableName);
    //        existingDBDatabase.Tables.Add(existingDBTable);
    //        DBKey existingDBKey = new DBKey { KeyName = dbKey.KeyName };
    //        existingDBTable.Keys.Add(existingDBKey);
    //        DBKeyColumn dbKeyCol = new DBKeyColumn();
    //        existingDBKey.KeyColumns.Add(dbKeyCol);
    //        //---------------Assert Precondition----------------
    //        Assert.AreEqual(1, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, newDBDatabase.Tables[0].Keys.Count);
    //        Assert.AreEqual(0, newDBDatabase.Tables[0].Keys[0].KeyColumns.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables[0].Keys.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables[0].Keys[0].KeyColumns.Count);
    //        Assert.AreEqual(ChangeType.None, dbKeyCol.PendingChangeType);
    //        //---------------Execute Test ----------------------
    //        DBBusinessObjectMerger dbBusinessObjectMerger = new DBBusinessObjectMerger(existingDBDatabase, null);
    //        dbBusinessObjectMerger.Import(newDBDatabase);
    //        //---------------Test Result -----------------------
    //        Assert.AreEqual(1, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, newDBDatabase.Tables[0].Keys.Count);
    //        Assert.AreEqual(0, newDBDatabase.Tables[0].Keys[0].KeyColumns.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables[0].Keys.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables[0].Keys[0].KeyColumns.Count);

    //        Assert.AreEqual(ChangeType.Delete, dbKeyCol.PendingChangeType);
    //        Assert.AreEqual(ChangeType.Update, existingDBKey.PendingChangeType);
    //        Assert.AreEqual(ChangeType.Update, existingDBTable.PendingChangeType);
    //    }

    //    // Test the situation where a Primary Key has been Added
    //    [Test]
    //    public void Test_Import_SameTable_PrimaryKeyAdded()
    //    {
    //        //---------------Set up test pack-------------------
    //        DBDatabase newDBDatabase = new DBDatabase();
    //        DBTable dbTable = new DBTable(TestUtils.GetRandomString());
    //        newDBDatabase.Tables.Add(dbTable);
    //        DBPrimaryKey dbPrimaryKey = new DBPrimaryKey();
    //        dbTable.PrimaryKeyDB = dbPrimaryKey;

    //        DBDatabase existingDBDatabase = new DBDatabase();
    //        DBTable existingDBTable = new DBTable(dbTable.TableName);
    //        existingDBDatabase.Tables.Add(existingDBTable);
    //        //---------------Assert Precondition----------------
    //        Assert.AreEqual(1, newDBDatabase.Tables.Count);
    //        Assert.IsNotNull(dbTable.PrimaryKeyDB);
    //        Assert.IsNotNull(newDBDatabase.Tables[0].PrimaryKeyDB);
    //        Assert.AreEqual(1, existingDBDatabase.Tables.Count);
    //        Assert.IsNull(existingDBTable.PrimaryKeyDB);
    //        Assert.AreEqual(ChangeType.None, dbPrimaryKey.PendingChangeType);
    //        //---------------Execute Test ----------------------
    //        DBBusinessObjectMerger dbBusinessObjectMerger = new DBBusinessObjectMerger(existingDBDatabase, null);
    //        dbBusinessObjectMerger.Import(newDBDatabase);
    //        //---------------Test Result -----------------------
    //        Assert.AreEqual(1, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables.Count);
    //        Assert.IsNotNull(existingDBTable.PrimaryKeyDB);
    //        Assert.AreSame(dbPrimaryKey, existingDBTable.PrimaryKeyDB);
    //        Assert.IsNull(dbTable.PrimaryKeyDB, "DBKey should have been moved");
    //        Assert.AreEqual(ChangeType.Add, dbPrimaryKey.PendingChangeType);
    //        Assert.AreEqual(ChangeType.Update, existingDBTable.PendingChangeType);
    //    }

    //    [Test]
    //    public void Test_SetPrimaryKey()
    //    {
    //        //---------------Set up test pack-------------------
    //        DBTable dbTable = new DBTable(TestUtils.GetRandomString());
    //        DBPrimaryKey dbPrimaryKey = new DBPrimaryKey();
    //        //---------------Assert Precondition----------------
    //        Assert.IsNotNull(dbPrimaryKey);
    //        //---------------Execute Test ----------------------
    //        dbTable.PrimaryKeyDB = dbPrimaryKey;
    //        //---------------Test Result -----------------------
    //        Assert.IsNotNull(dbTable.PrimaryKeyDB, "Primary key should not be null");
    //        Assert.AreSame(dbPrimaryKey, dbTable.PrimaryKeyDB);
    //    }
    //    // Test the situation where a Primary Key has been Deleted
    //    [Test]
    //    public void Test_Import_SameTable_PrimaryKeyDeleted()
    //    {
    //        //---------------Set up test pack-------------------
    //        DBDatabase newDBDatabase = new DBDatabase();
    //        DBTable dbTable = new DBTable(TestUtils.GetRandomString());
    //        newDBDatabase.Tables.Add(dbTable);

    //        DBDatabase existingDBDatabase = new DBDatabase();
    //        DBTable existingDBTable = new DBTable(dbTable.TableName);
    //        existingDBDatabase.Tables.Add(existingDBTable);
    //        DBPrimaryKey dbPrimaryKey = new DBPrimaryKey();
    //        existingDBTable.PrimaryKeyDB = dbPrimaryKey;
    //        //---------------Assert Precondition----------------
    //        Assert.AreEqual(1, newDBDatabase.Tables.Count);
    //        Assert.IsNull(newDBDatabase.Tables[0].PrimaryKeyDB);
    //        Assert.AreEqual(1, existingDBDatabase.Tables.Count);
    //        Assert.IsNotNull(existingDBTable.PrimaryKeyDB);
    //        Assert.AreEqual(ChangeType.None, dbPrimaryKey.PendingChangeType);
    //        //---------------Execute Test ----------------------
    //        DBBusinessObjectMerger dbBusinessObjectMerger = new DBBusinessObjectMerger(existingDBDatabase, null);
    //        dbBusinessObjectMerger.Import(newDBDatabase);
    //        //---------------Test Result -----------------------
    //        Assert.AreEqual(1, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables.Count);
    //        Assert.IsNotNull(existingDBTable.PrimaryKeyDB);
    //        Assert.AreSame(dbPrimaryKey, existingDBTable.PrimaryKeyDB);
    //        Assert.AreEqual(ChangeType.Delete, dbPrimaryKey.PendingChangeType);
    //        Assert.AreEqual(ChangeType.Update, existingDBTable.PendingChangeType);
    //    }

    //    //// Test the situation where a Database Primary Key Column has been Added (PK Changed)
    //    [Test]
    //    public void Test_Import_SameTable_PrimaryKeyColumnAdded()
    //    {
    //        //---------------Set up test pack-------------------
    //        DBDatabase newDBDatabase = new DBDatabase();
    //        DBTable dbTable = new DBTable(TestUtils.GetRandomString());
    //        newDBDatabase.Tables.Add(dbTable);
    //        dbTable.PrimaryKeyDB = new DBPrimaryKey();
    //        DBPrimaryKeyColumn dbPrimaryKeyColumn = new DBPrimaryKeyColumn();
    //        dbTable.PrimaryKeyDB.PrimaryKeyColumns.Add(dbPrimaryKeyColumn);

    //        DBDatabase existingDBDatabase = new DBDatabase();
    //        DBTable existingDBTable = new DBTable(dbTable.TableName);
    //        existingDBDatabase.Tables.Add(existingDBTable);
    //        existingDBTable.PrimaryKeyDB = new DBPrimaryKey();
    //        DBBusinessObjectMerger dbBusinessObjectMerger = new DBBusinessObjectMerger(existingDBDatabase, null);
    //        //businessObjectMerger.AddSingleRelationshipToTraverse(typeof(Table), "DBPrimaryKey");
    //        //---------------Assert Precondition----------------
    //        Assert.AreEqual(1, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, newDBDatabase.Tables[0].PrimaryKeyDB.PrimaryKeyColumns.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables.Count);
    //        Assert.AreEqual(0, existingDBDatabase.Tables[0].PrimaryKeyDB.PrimaryKeyColumns.Count);
    //        Assert.AreEqual(ChangeType.None, dbPrimaryKeyColumn.PendingChangeType);
    //        //---------------Execute Test ----------------------
    //        dbBusinessObjectMerger.Import(newDBDatabase);
    //        //---------------Test Result -----------------------
    //        Assert.AreEqual(1, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(0, newDBDatabase.Tables[0].PrimaryKeyDB.PrimaryKeyColumns.Count, "This is expected to be moved");
    //        Assert.AreEqual(1, existingDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables[0].PrimaryKeyDB.PrimaryKeyColumns.Count);

    //        Assert.AreEqual(ChangeType.Add, dbPrimaryKeyColumn.PendingChangeType);
    //        Assert.AreEqual(ChangeType.Update, existingDBTable.PrimaryKeyDB.PendingChangeType);
    //        Assert.AreEqual(ChangeType.Update, existingDBTable.PendingChangeType);
    //    }

    //    // Test the situation where a Database Primary Key Column has been Deleted (PK Changed)
    //    [Test]
    //    public void Test_Import_SameTable_PrimaryKeyColumnDeleted()
    //    {
    //        //---------------Set up test pack-------------------
    //        DBDatabase newDBDatabase = new DBDatabase();
    //        DBTable dbTable = new DBTable(TestUtils.GetRandomString());
    //        newDBDatabase.Tables.Add(dbTable);
    //        dbTable.PrimaryKeyDB = new DBPrimaryKey();

    //        DBDatabase existingDBDatabase = new DBDatabase();
    //        DBTable existingDBTable = new DBTable(dbTable.TableName);
    //        existingDBDatabase.Tables.Add(existingDBTable);
    //        existingDBTable.PrimaryKeyDB = new DBPrimaryKey();
    //        DBPrimaryKeyColumn dbPrimaryKeyColumn = new DBPrimaryKeyColumn();
    //        existingDBTable.PrimaryKeyDB.PrimaryKeyColumns.Add(dbPrimaryKeyColumn);

    //        DBBusinessObjectMerger dbBusinessObjectMerger = new DBBusinessObjectMerger(existingDBDatabase, null);
    //        //businessObjectMerger.AddSingleRelationshipToTraverse(typeof(Table), "DBPrimaryKey");
    //        //---------------Assert Precondition----------------
    //        Assert.AreEqual(1, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(0, newDBDatabase.Tables[0].PrimaryKeyDB.PrimaryKeyColumns.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables[0].PrimaryKeyDB.PrimaryKeyColumns.Count);
    //        Assert.AreEqual(ChangeType.None, dbPrimaryKeyColumn.PendingChangeType);
    //        //---------------Execute Test ----------------------
    //        dbBusinessObjectMerger.Import(newDBDatabase);
    //        //---------------Test Result -----------------------
    //        Assert.AreEqual(1, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(0, newDBDatabase.Tables[0].PrimaryKeyDB.PrimaryKeyColumns.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables[0].PrimaryKeyDB.PrimaryKeyColumns.Count);

    //        Assert.AreEqual(ChangeType.Delete, dbPrimaryKeyColumn.PendingChangeType);
    //        Assert.AreEqual(ChangeType.Update, existingDBTable.PrimaryKeyDB.PendingChangeType);
    //        Assert.AreEqual(ChangeType.Update, existingDBTable.PendingChangeType);
    //    }

    //    // Test the situation where a Foreign Key Column has been Added
    //    [Test]
    //    public void Test_Import_SameTable_ForeignKey_ColumnAdded()
    //    {
    //        //---------------Set up test pack-------------------
    //        DBDatabase newDBDatabase = new DBDatabase();
    //        DBTable dbTable = new DBTable(TestUtils.GetRandomString());
    //        newDBDatabase.Tables.Add(dbTable);
    //        DBForeignKey dbForeignKey = new DBForeignKey();
    //        dbTable.ForeignKeys.Add(dbForeignKey);
    //        DBForeignKeyColumn foreignkeyCol = new DBForeignKeyColumn();
    //        dbForeignKey.ForeignKeyColumns.Add(foreignkeyCol);

    //        DBDatabase existingDBDatabase = new DBDatabase();
    //        DBTable existingDBTable = new DBTable(dbTable.TableName);
    //        existingDBDatabase.Tables.Add(existingDBTable);
    //        DBForeignKey existingDBForeignKey = new DBForeignKey();
    //        existingDBTable.ForeignKeys.Add(existingDBForeignKey);

    //        //---------------Assert Precondition----------------
    //        Assert.AreEqual(1, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, newDBDatabase.Tables[0].ForeignKeys.Count);
    //        Assert.AreEqual(1, newDBDatabase.Tables[0].ForeignKeys[0].ForeignKeyColumns.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables[0].ForeignKeys.Count);
    //        Assert.AreEqual(0, existingDBDatabase.Tables[0].ForeignKeys[0].ForeignKeyColumns.Count);
    //        Assert.AreEqual(ChangeType.None, foreignkeyCol.PendingChangeType);
    //        //---------------Execute Test ----------------------
    //        DBBusinessObjectMerger dbBusinessObjectMerger = new DBBusinessObjectMerger(existingDBDatabase, null);
    //        dbBusinessObjectMerger.Import(newDBDatabase);
    //        //---------------Test Result -----------------------
    //        Assert.AreEqual(1, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, newDBDatabase.Tables[0].ForeignKeys.Count);
    //        Assert.AreEqual(0, newDBDatabase.Tables[0].ForeignKeys[0].ForeignKeyColumns.Count, "This is expected to be moved");
    //        Assert.AreEqual(1, existingDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables[0].ForeignKeys.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables[0].ForeignKeys[0].ForeignKeyColumns.Count);

    //        Assert.AreEqual(ChangeType.Add, foreignkeyCol.PendingChangeType);
    //        Assert.AreEqual(ChangeType.Update, existingDBForeignKey.PendingChangeType);
    //        Assert.AreEqual(ChangeType.Update, existingDBTable.PendingChangeType);
    //    }

    //    //// Test the situation where a Database ForeignKey Column has been Deleted
    //    [Test]
    //    public void Test_Import_SameTable_ForeignKey_ColumnDeleted()
    //    {
    //        //---------------Set up test pack-------------------
    //        DBDatabase newDBDatabase = new DBDatabase();
    //        DBTable dbTable = new DBTable(TestUtils.GetRandomString());
    //        newDBDatabase.Tables.Add(dbTable);
    //        DBForeignKey dbForeignKey = new DBForeignKey();
    //        dbTable.ForeignKeys.Add(dbForeignKey);


    //        DBDatabase existingDBDatabase = new DBDatabase();
    //        DBTable existingDBTable = new DBTable(dbTable.TableName);
    //        existingDBDatabase.Tables.Add(existingDBTable);
    //        DBForeignKey existingDBForeignKey = new DBForeignKey();
    //        existingDBTable.ForeignKeys.Add(existingDBForeignKey);
    //        DBForeignKeyColumn foreignkeyCol = new DBForeignKeyColumn();
    //        existingDBForeignKey.ForeignKeyColumns.Add(foreignkeyCol);

    //        //---------------Assert Precondition----------------
    //        Assert.AreEqual(1, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, newDBDatabase.Tables[0].ForeignKeys.Count);
    //        Assert.AreEqual(0, newDBDatabase.Tables[0].ForeignKeys[0].ForeignKeyColumns.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables[0].ForeignKeys.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables[0].ForeignKeys[0].ForeignKeyColumns.Count);
    //        Assert.AreEqual(ChangeType.None, foreignkeyCol.PendingChangeType);
    //        //---------------Execute Test ----------------------
    //        DBBusinessObjectMerger dbBusinessObjectMerger = new DBBusinessObjectMerger(existingDBDatabase, null);
    //        dbBusinessObjectMerger.Import(newDBDatabase);
    //        //---------------Test Result -----------------------
    //        Assert.AreEqual(1, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, newDBDatabase.Tables[0].ForeignKeys.Count);
    //        Assert.AreEqual(0, newDBDatabase.Tables[0].ForeignKeys[0].ForeignKeyColumns.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables[0].ForeignKeys.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables[0].ForeignKeys[0].ForeignKeyColumns.Count);

    //        Assert.AreEqual(ChangeType.Delete, foreignkeyCol.PendingChangeType);
    //        Assert.AreEqual(ChangeType.Update, existingDBForeignKey.PendingChangeType);
    //        Assert.AreEqual(ChangeType.Update, existingDBTable.PendingChangeType);
    //    }

    //    //// Test the situation where a  ForeignKey Column has been changed
    //    [Test, Ignore]// Mark to help here????
    //    public void Test_Import_SameTable_ForeignKey_ColumnChanged()
    //    {
    //        //---------------Set up test pack-------------------
    //        DBDatabase newDBDatabase = new DBDatabase();
    //        DBTable dbTable = new DBTable(TestUtils.GetRandomString());
    //        newDBDatabase.Tables.Add(dbTable);
    //        DBForeignKey dbForeignKey = new DBForeignKey();
    //        dbTable.ForeignKeys.Add(dbForeignKey);
    //        DBForeignKeyColumn foreignkeyCol = new DBForeignKeyColumn();
    //        DBForeignKeyColumn newForeignkeyCol = new DBForeignKeyColumn();
    //        dbForeignKey.ForeignKeyColumns.Add(foreignkeyCol);
    //        dbForeignKey.ForeignKeyColumns.Add(newForeignkeyCol);

    //        DBDatabase existingDBDatabase = new DBDatabase();
    //        DBTable existingDBTable = new DBTable(dbTable.TableName);
    //        existingDBDatabase.Tables.Add(existingDBTable);
    //        DBForeignKeyColumn existingForeignkeyCol = new DBForeignKeyColumn();
    //        DBForeignKey existingDBForeignKey = new DBForeignKey();
    //        existingDBTable.ForeignKeys.Add(existingDBForeignKey);
    //        existingDBForeignKey.ForeignKeyColumns.Add(existingForeignkeyCol);

    //        //---------------Assert Precondition----------------
    //        Assert.AreEqual(1, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, newDBDatabase.Tables[0].ForeignKeys.Count);
    //        Assert.AreEqual(2, newDBDatabase.Tables[0].ForeignKeys[0].ForeignKeyColumns.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables[0].ForeignKeys.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables[0].ForeignKeys[0].ForeignKeyColumns.Count);
    //        Assert.AreEqual(ChangeType.None, foreignkeyCol.PendingChangeType);
    //        //---------------Execute Test ----------------------
    //        DBBusinessObjectMerger dbBusinessObjectMerger = new DBBusinessObjectMerger(existingDBDatabase, null);
    //        dbBusinessObjectMerger.Import(newDBDatabase);
    //        //---------------Test Result -----------------------
    //        Assert.AreEqual(1, newDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, newDBDatabase.Tables[0].ForeignKeys.Count);
    //        Assert.AreEqual(1, newDBDatabase.Tables[0].ForeignKeys[0].ForeignKeyColumns.Count, "OneColumn Info Moved");
    //        Assert.AreEqual(1, existingDBDatabase.Tables.Count);
    //        Assert.AreEqual(1, existingDBDatabase.Tables[0].ForeignKeys.Count);
    //        Assert.AreEqual(2, existingDBDatabase.Tables[0].ForeignKeys[0].ForeignKeyColumns.Count);

    //        Assert.AreEqual(ChangeType.Delete, foreignkeyCol.PendingChangeType);
    //        Assert.AreEqual(ChangeType.Update, existingDBForeignKey.PendingChangeType);
    //        Assert.AreEqual(ChangeType.Update, existingDBTable.PendingChangeType);
    //    }
    //}
}
